package com.rules.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.entity.GroupUserModel;
import com.rules.admin.login.UserHolder;
import com.rules.admin.service.GroupUserService;
import com.rules.admin.utils.ResultUtils;
import com.rules.admin.vo.RuleUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RequestMapping({"/groupUser"})
@Controller
public class GroupUserController {
   @Autowired
   private GroupUserService groupUserService;
   @Autowired
   private UserHolder<RuleUser> userHolder;

   @RequestMapping(
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<GroupUserModel> queryPage(Long groupId, String username, IPage<GroupUserModel> page) {
      return this.groupUserService.queryPage(groupId, username, page);
   }

   @RequestMapping(
      value = {"/account"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getAccount(HttpServletRequest request) {
      RuleUser ruleUser = (RuleUser)this.userHolder.getUser();
      return ruleUser.equals(RuleUser.ANONYMOUS_USER) ? ResultUtils.getFaildResultData() : ResultUtils.getSuccessResultData(this.groupUserService.getAccount(ruleUser.getId()));
   }
}
